package com.server.util;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Busline: sunguangzhu
 * Date: 13-8-9
 * Time: 下午3:18
 * To change this template use File | Settings | File Templates.
 */
public class JpaAnnotationUtils {
    public static List<String> getJapAnnotationList(String annotationFlag, Field field, Class clazz) {
        List<String> list = new ArrayList<String>();
        if (annotationFlag.equals("normal")) {
            list.add("@Column");
        } else if (annotationFlag.equals("ManyToOne")) {
            list.add("@JsonManagedReference");
            list.add("@ManyToOne(fetch = FetchType.EAGER)");
            list.add("@JoinColumn(name = \"" + field.getName() + "_id" + "\")");
            list.add("@NotFound(action = NotFoundAction.IGNORE)");
            list.add("@ForeignKey(name = \"" + "fk_" + clazz.getSimpleName().toLowerCase() + "_" + field.getName() + "\")");
        } else if (annotationFlag.equals("OneToMany")) {
            list.add("@JsonBackReference");
//            list.add("@OneToMany(fetch = FetchType.LAZY, mappedBy = \"" + (ReflectUtil.parSetName(clazz.getSimpleName())).replace("set", "") + "\")");
            list.add("@OneToMany(fetch = FetchType.LAZY, mappedBy = \"" + Utils.transformerString(clazz.getSimpleName())+ "\")");
        }
        return list;
    }
}
